﻿/**
 * Peter
 * 
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *    
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *  
 **/
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Peter.Logic;
using Peter.Logic.EventArguments;

namespace Peter.Tests.Logic
{
   /// <summary>
   /// Tests the argument service.
   /// </summary>
   [TestClass]
   public class ArgumentServiceTests
   {
      private bool m_EventRaised;
      private const string ARGUMENT = "TestArgument";

      /// <summary>
      /// Adds an argument to the service and checks to see if
      /// collection is updated and event is raised.
      /// </summary>
      [TestMethod]
      public void AddingArgument ()
      {
         ArgumentService.Instance.ArgumentAdded += this.ArgumentAdded;
         ArgumentService.Instance.AddArgument (ARGUMENT);
         Assert.IsTrue (ArgumentService.Instance.Arguments.Contains (ARGUMENT));
         Assert.IsTrue (this.m_EventRaised);
      }

      /// <summary>
      /// Occurs when an argument has been added.
      /// </summary>
      /// <param name="sender">Sender of the event.</param>
      /// <param name="e"></param>
      private void ArgumentAdded (object sender, ArgumentEventArgs e)
      {
         Assert.AreEqual (ARGUMENT, e.Argument);
         this.m_EventRaised = true;
      }

      /// <summary>
      /// Adds a null argument, for an expected exception.
      /// </summary>
      [TestMethod]
      [ExpectedException (typeof (ArgumentNullException))]
      public void NullArgument ()
      {
         ArgumentService.Instance.AddArgument (null);
      }

   }
}
